package com.zr.repertory.inventorySettings.controller;

import com.zr.inventorySettings.pojo.*;
import com.zr.inventorySettings.service.InventoryService;
import com.zr.util.ResultBuilderVo;
import com.zr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Calm on 2019/11/20.
 */
@RestController
@CrossOrigin
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;

                                                    /*
                                                        库房标识部分
                                                    */
    /*新增库房标识接口*/
    @PostMapping("identification/add")
    public ResultVo identificationAdd(@RequestBody WarehousemarkAddVo warehousemarkAddVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.identificationAdd(warehousemarkAddVo);
    }

    /*库房标识查询接口*/
    @PostMapping("identification/query")
    public ResultVo identificationQuery(@RequestBody WarehousemarkSelectVo warehousemarkSelectVo){
        return inventoryService.identificationQuery(warehousemarkSelectVo);
    }

    /*库房标识修改接口*/
    @PostMapping("identification/update")
    public ResultVo identificationUpdate(@RequestBody WarehousemarkUpdateVo warehousemarkUpdateVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.identificationUpdate(warehousemarkUpdateVo);
    }

    /*库房标识启用/禁用接口*/
    @PostMapping("identification/updateStatus")
    public ResultVo identificationUpdateStatus(@RequestBody WarehousemarkUpdateStatusVo warehousemarkUpdateStatusVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        //如果没有错误跳到service层进行逻辑处理
        ResultVo resultVo =  inventoryService.identificationUpdateStatus(warehousemarkUpdateStatusVo);
        return resultVo;
    }


                                                        /*
                                                        库房部分
                                                        */
    /*新增库房接口*/
    @PostMapping("room/add")
    public ResultVo roomAdd(@RequestBody WarehouseAddVo warehouseAddVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.roomAdd(warehouseAddVo);
    }

    /*库房查询接口*/
    @PostMapping("room/querypage")
    public ResultVo roomQuerypage(@RequestBody WarehouseSelectVo warehouseSelectVo){
        return inventoryService.roomQuerypage(warehouseSelectVo);
    }

    /*库房修改接口*/
    @PostMapping("room/update")
    public ResultVo roomUpdate(@RequestBody WarehouseUpdateVo warehouseUpdateVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.roomUpdate(warehouseUpdateVo);
    }

    /*库房启用/禁用接口*/
    @PostMapping("room/updateStatus")
    public ResultVo roomUpdateStatus(@RequestBody WarehousemarkUpdateStatusVo warehousemarkUpdateStatusVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        //如果没有错误跳到service层进行逻辑处理
        ResultVo resultVo =  inventoryService.roomUpdateStatus(warehousemarkUpdateStatusVo);
        return resultVo;
    }


                                                    /*
                                                        库区属性部分
                                                    */
    /*新增库区属性接口*/
    @PostMapping("attribute/add")
    public ResultVo attributeAdd(@RequestBody ReservoirareapropertiesAddVo reservoirareapropertiesAddVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.attributeAdd(reservoirareapropertiesAddVo);
    }

    /*库区属性查询接口*/
    @PostMapping("attribute/query")
    public ResultVo attributeQuery(@RequestBody ReservoirareapropertiesSelectVo reservoirareapropertiesSelectVo){
        return inventoryService.attributeQuery(reservoirareapropertiesSelectVo);
    }

    /*库区属性修改接口*/
    @PostMapping("attribute/update")
    public ResultVo attributeUpdate(@RequestBody ReservoirareapropertiesUpdateVo reservoirareapropertiesUpdateVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.attributeUpdate(reservoirareapropertiesUpdateVo);
    }

    /*  库区属性启用/禁用接口*/
    @PostMapping("attribute/updateStatus")
    public ResultVo attributeUpdateStatus(@RequestBody WarehousemarkUpdateStatusVo warehousemarkUpdateStatusVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        //如果没有错误跳到service层进行逻辑处理
        ResultVo resultVo =  inventoryService.attributeUpdateStatus(warehousemarkUpdateStatusVo);
        return resultVo;
    }

                                                /*
                                                    库区部分
                                                */
    /*库房编码下拉框接口*/
    @PostMapping("room/xiala")
    public ResultVo roomXiala(){
        return inventoryService.roomXiala();
    }

    /*新增库区接口*/
    @PostMapping("roomarea/add")
    public ResultVo roomareaAdd(@RequestBody ReservoirareaAddVo reservoirareaAddVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.roomareaAdd(reservoirareaAddVo);
    }

    /*库区分页接口*/
    @PostMapping(" roomarea/querypage")
    public ResultVo roomareaQuerypage(@RequestBody ReservoirareaSelectVo reservoirareaSelectVo){
        return inventoryService.roomareaQuerypage(reservoirareaSelectVo);
    }

    /*库区修改接口*/
    @PostMapping("roomarea/update")
    public ResultVo roomareaUpdate(@RequestBody ReservoirareaUpdateVo reservoirareaUpdateVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.roomareaUpdate(reservoirareaUpdateVo);
    }

    /*库区查看接口*/
    @PostMapping("roomarea/see")
    public ResultVo roomareaSee(@RequestBody ReservoirareaSeeVo reservoirareaSeeVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.roomareaSee(reservoirareaSeeVo);
    }

    /* 库区启用/禁用接口*/
    @PostMapping("roomarea/updateStatus")
    public ResultVo roomareaUpdateStatus(@RequestBody WarehousemarkUpdateStatusVo warehousemarkUpdateStatusVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        //如果没有错误跳到service层进行逻辑处理
        ResultVo resultVo =  inventoryService.roomareaUpdateStatus(warehousemarkUpdateStatusVo);
        return resultVo;
    }

                                                /*
                                                    库位部分
                                                */

    /*库区编码下拉框接口*/
    @PostMapping("roomspace/xiala")
    public ResultVo roomSpaceXiala(@RequestBody ReservoirareaSelectVo reservoirareaSelectVo){
        return inventoryService.roomSpaceXiala(reservoirareaSelectVo.getWarehouseid());
    }

    /*根据库区编码展示原有的库位信息*/
    @PostMapping("roomspace/kuwei")
    public ResultVo roomSpaceKuwei(@RequestBody ReservoirareaSelectVo reservoirareaSelectVo){
        return inventoryService.roomSpaceKuwei(reservoirareaSelectVo.getReservoirareaid());
    }

     /*库位新增接口*/
     @PostMapping("roomspace/add")
     public ResultVo roomSpaceAdd(@RequestBody StoragelocationAddVo storagelocationAddVo,BindingResult bindingResult){
         //判断是否存在错误信息
         if (bindingResult.hasErrors()){
             //如果存在return给页面错误信息
             return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
         }
         return inventoryService.roomSpaceAdd(storagelocationAddVo);
     }

     /*库位分页查询接口*/
     @PostMapping("roomspace/querypage")
     public ResultVo roomSpaceQuerypage(@RequestBody StoragelocationSelectVo storagelocationSelectVo){
         return inventoryService.roomSpaceQuerypage(storagelocationSelectVo);
     }

    /*库位修改接口*/
    @PostMapping("roomspace/update")
    public ResultVo roomSpaceUpdate(@RequestBody StoragelocationUpdateVo storagelocationUpdateVo,BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.roomSpaceUpdate(storagelocationUpdateVo);
    }

    /* 库位启用/禁用接口*/
    @PostMapping("roomspace/updateStatus")
    public ResultVo roomspaceUpdateStatus(@RequestBody WarehousemarkUpdateStatusVo warehousemarkUpdateStatusVo, BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        //如果没有错误跳到service层进行逻辑处理
        ResultVo resultVo =  inventoryService.roomspaceUpdateStatus(warehousemarkUpdateStatusVo);
        return resultVo;
    }


                                                /*
                                                    库房归属部分
                                                */
    /*库房归属分页查询接口*/
    @PostMapping("belongings/querypage")
    public ResultVo belongingsQuerypage(@RequestBody DeoptBelongVo deoptBelongVo){
        return inventoryService.belongingsQuerypage(deoptBelongVo);
    }

    /*库房归属查看接口*/
    @GetMapping("belongings/see")
    public ResultVo see(Integer LegalPersonId){
        DeopBelongSeeVo deopBelongSeeVo = inventoryService.see(LegalPersonId);
        return ResultBuilderVo.success(deopBelongSeeVo);
    }

    /*多条件查询展示所有库房的信息*/
    @PostMapping("queryWarehouse")
    public ResultVo queryAllWareHouse(WarehouseSelectVo warehouseSelectVo){
        List<Warehouse> wareHouseList = inventoryService.queryAllWareHouse(warehouseSelectVo);
        return ResultBuilderVo.success(wareHouseList);
    }

    /*根据勾选的库房信息查库区信息*/
    @PostMapping("queryReservoirarea")
    public ResultVo queryReservoirarea(WarehouseSelectVo warehouseSelectVo){
        List<Reservoirarea> reservoirareaList = inventoryService.queryReservoirarea(warehouseSelectVo.getWarehouseid());
        return ResultBuilderVo.success(reservoirareaList);
    }

    /*根据勾选的库区信息查库位信息*/
    @PostMapping("queryStoragelocation")
    public ResultVo queryStoragelocation(ReservoirareaSelectVo reservoirareaSelectVo){
        List<Storagelocation> storagelocationList = inventoryService.queryStoragelocation(reservoirareaSelectVo.getReservoirareaid());
        return ResultBuilderVo.success(storagelocationList);
    }

    /*根据法人查对应的库位库区库房信息*/
    @PostMapping("queryStoragelocationAndLegalPerson")
    public ResultVo queryStoragelocationAndLegalPerson(Integer LegalPersonId){
        DeopBelongSeeVo deopBelongSeeVo = inventoryService.queryStoragelocationAndLegalPerson(LegalPersonId);
        return ResultBuilderVo.success(deopBelongSeeVo);
    }

    /*根据库位信息查对应的库区信息*//*
    @PostMapping("queryReservoirareaAndLegalPerson")
    public ResultVo queryReservoirareaAndLegalPerson(StoragelocationSelectVo  storagelocationSelectVo){
        List<Reservoirarea> reservoirareaList = inventoryService.queryReservoirareaAndLegalPerson(storagelocationSelectVo.getStoragelocationid());
        return ResultBuilderVo.success(reservoirareaList);
    }
    *//*根据库区信息查对应的库房信息*//*
    @PostMapping("queryWarehouseAndLegalPerson")
    public ResultVo queryWarehouseAndLegalPerson(ReservoirareaSelectVo  reservoirareaSelectVo){
        List<Warehouse> warehouseList = inventoryService.queryWarehouseAndLegalPerson(reservoirareaSelectVo.getReservoirareaid());
        return ResultBuilderVo.success(warehouseList);
    }*/

    /*根据库区属性下拉框查库区信息*/
    @PostMapping("queryReservoirPropertiesAndReservoir")
    public ResultVo queryReservoirPropertiesAndReservoir(Integer  reservoirPropertiesId){
        List<Reservoirarea> reservoirareaList = inventoryService.queryReservoirPropertiesAndReservoir(reservoirPropertiesId);
        return ResultBuilderVo.success(reservoirareaList);
    }

    /*库房归属新增接口*/
    @PostMapping("belongings/add")
    public ResultVo belongingsAdd(@RequestBody Legalpersonandstoragelocation legalpersonandstoragelocation,BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.belongingsAdd(legalpersonandstoragelocation);
    }

    /*库房归属修改接口*/
    @PostMapping("belongings/update")
    public ResultVo belongingsUpdate(@RequestBody Legalpersonandstoragelocation legalpersonandstoragelocation,BindingResult bindingResult){
        //判断是否存在错误信息
        if (bindingResult.hasErrors()){
            //如果存在return给页面错误信息
            return ResultBuilderVo.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
        return inventoryService.belongingsUpdate(legalpersonandstoragelocation);
    }



}
